package com.yihuier.yihuier.Service.UserManager;

import com.yihuier.yihuier.Mapper.UserManager.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class MessageService {

    @Autowired
    private MessageMapper messageMapper;
    /**
     * 更改消息读状态
     */
    public int updateMessageReadStatusupdate(int message_id) {
        return messageMapper.updateMessageReadStatus(message_id);
    }

    /**
     * 删除消息读状态
     */
    public int deleteMessageReadStatusupdate(int message_id) {
        return messageMapper.deleteMessageReadStatus(message_id);
    }

    /**
     * 得到用户收到消息
     */
    public List<Map<String, Object>> getMessages(int user_id, int[] managerIds) {
        return messageMapper.selectMessages(user_id, managerIds);
    }

    /**
     * 向数据库中插入消息
     * */
    public int addMessage(int message_from_id,int message_to_id, String message_content){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设定时间格式规范
        String message_datetime = sdf.format(new Date());
        return messageMapper.insertMessage(message_from_id, message_to_id, message_content,message_datetime);
    }

    public List<Map<String,Object>> getAllMessageFromManagerSelf(int manager_id){
        return messageMapper.selectAllMessageFromManagerSelf(manager_id);
    }
}
